<?php
class Common_Controller_Action_Helper_ModuleSetup extends Zend_Controller_Action_Helper_Abstract
{
 
	public  function preDispatch()
	{
            $bootstrap = $this -> getActionController()
                                -> getInvokeArg('bootstrap');
            $config = $bootstrap -> getOptions();
            $module = $this -> getRequest() -> getModuleName();
            $controller = $this -> getRequest()->getControllerName();
        
            $view = $this->getActionController()->view;
            //$fb_flag = $this->getRequest()->getParam('fb');//check for facebook subdomain
            $view->module = $module;
	    $view->page = $module;
            $view->controller = $controller;
                    if(isset($config[$module]['resources']['layout']['layout']) and !$this->getRequest()->isXmlHttpRequest()){
                            $layoutPath = $config[$module]['resources']['layout']['layoutPath'];
                            $layoutScript = $config[$module]['resources']['layout']['layout'];
                            //if separate facebook layout specified we will use it
                            $this -> getActionController()
                            -> getHelper('layout')
							-> setLayoutPath($layoutPath)
                            -> setLayout($layoutScript);
                            
                    }
            if(isset($config[$module]['url']['base'])){
                            $url = $config[$module]['url']['base'];
                            $front = Zend_Controller_Front::getInstance();

                $front->setBaseUrl($url);

                    }
                    
	}
}